package com.avic.map.common.convertor;


import com.avic.map.common.constant.AppConstant;
import com.avic.map.controller.info.EmergencyFireSignInfo;
import com.avic.map.controller.info.EmergencyInfo;
import com.avic.map.dal.model.Emergency;
import com.avic.map.dal.model.EmergencyFireSign;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * 地图船舶资源对象转换器
 *
 * @author huangsheng
 */
public class EmergencyConvertor {

    public static List<EmergencyInfo> emergenciesToEmergencyInfo(List<Emergency> emergencies) {
        if (null != emergencies && emergencies.size() > 0) {
            List<EmergencyInfo> emergencyInfos = new ArrayList<>(emergencies.size());
            emergencies.forEach(emergencie -> {
                EmergencyInfo emergencyInfo = new EmergencyInfo();
                emergencyInfo.setCreateDate(emergencie.getCreateDate());
                emergencyInfo.setEndTime(StringUtils.isNotBlank(emergencie.getEndTime()) ?
                        StringUtils.substringBefore(emergencie.getEndTime(), AppConstant.MYBATIS_DATA_TIME_SEPARATOR) : StringUtils.EMPTY);
                emergencyInfo.setId(emergencie.getId());
                emergencyInfo.setStartTime(StringUtils.isNotBlank(emergencie.getStartTime()) ?
                        StringUtils.substringBefore(emergencie.getStartTime(), AppConstant.MYBATIS_DATA_TIME_SEPARATOR) : StringUtils.EMPTY);
                emergencyInfo.setEmergencyName(emergencie.getEmergencyName());
                emergencyInfos.add(emergencyInfo);
            });
            return emergencyInfos;
        }
        return new ArrayList<>();
    }

    public static List<EmergencyFireSignInfo> emergencyFireSignsToEmergencyFireSignInfo(List<EmergencyFireSign> emergencyFireSigns) {
        if (null != emergencyFireSigns && emergencyFireSigns.size() > 0) {
            List<EmergencyFireSignInfo> emergencyFireSignInfos = new ArrayList<>(emergencyFireSigns.size());
            emergencyFireSigns.forEach(emergencyFireSign -> {
                EmergencyFireSignInfo emergencyFireSignInfo = new EmergencyFireSignInfo();
                emergencyFireSignInfo.setEmergencyNumber(emergencyFireSign.getEmergencyNumber());
                emergencyFireSignInfo.setFireDetail(emergencyFireSign.getFireDetail());
                emergencyFireSignInfo.setFireLevel(emergencyFireSign.getFireLevel());
                emergencyFireSignInfo.setFireNature(emergencyFireSign.getFireNature());
                emergencyFireSignInfo.setFirePosition(emergencyFireSign.getFirePosition());
                emergencyFireSignInfo.setId(emergencyFireSign.getId());
                emergencyFireSignInfo.setLatitude(emergencyFireSign.getLatitude());
                emergencyFireSignInfo.setLongitude(emergencyFireSign.getLongitude());
                emergencyFireSignInfos.add(emergencyFireSignInfo);
            });
            return emergencyFireSignInfos;
        }
        return new ArrayList<>();
    }
}
